package config

import (
	"github.com/spf13/viper"
	"log"
)

type AppConfig struct {
	Mysql
	Rabbit
	TextSafe
}
type Mysql struct {
	Host     string
	Port     int
	User     string
	Password string
	DataBase string
}

type Rabbit struct {
	Username string
	Password string
	Host     string
	Port     int
	Vhost    string
}
type TextSafe struct {
	Ak string
	Sk string
}

var ConfigData AppConfig

func Init() {
	viper.SetConfigFile("config/dev.yaml")
	err := viper.ReadInConfig()
	if err != nil {
		panic("动态配置读取失败")
	}
	err = viper.Unmarshal(&ConfigData)
	if err != nil {
		panic("动态配置解析失败")
	}
	log.Println("动态配置解析成功", ConfigData)
}
